<?php

class Application_Form_Admin_CreateUserForm extends Zend_Form {

	public function init() {
		$this->setName('createuser');

		$this->setMethod(Zend_Form::METHOD_POST)
		->setEnctype(Zend_Form::ENCTYPE_URLENCODED);

		$id = new Zend_Form_Element_Hidden('id');
		$id->addFilter('Int')
		->setDecorators(array('ViewHelper','FormErrors'));

		$login = new Zend_Form_Element_Text('login');
		$login->setRequired('true')
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->addValidator('NotEmpty')
		->setDecorators(array('ViewHelper','FormErrors','Label','Errors'))
		->setAttrib("class", "menu-input")
		->setAttrib("autocomplete", "off")
		->setAttrib("onKeyup", "loginExists($('#login').val())");

		$nom = new Zend_Form_Element_Text('nom');
		$nom->setRequired('true')
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->addValidator('NotEmpty')
		->setAttrib("autocomplete", "off")
		->setDecorators(array('ViewHelper','FormErrors','Label','Errors'))
		->setAttrib("class", "menu-input");

		$prenom = new Zend_Form_Element_Text('prenom');
		$prenom->setRequired('true')
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->addValidator('NotEmpty')
		->setAttrib("autocomplete", "off")
		->setDecorators(array('ViewHelper','FormErrors','Label','Errors'))
		->setAttrib("class", "menu-input");

		$promo = new Zend_Form_Element_Text('promo');
		$promo->setRequired('true')
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->addValidator('NotEmpty')
		->setDecorators(array('ViewHelper','FormErrors','Label','Errors'))
		->setAttrib("class", "menu-input");

		$pwd_enable = new Zend_Form_Element_Checkbox('noGroup');
		$pwd_enable->setValue(0)
		->setAttrib('checked', 'checked')
		->setDecorators(array('ViewHelper','FormErrors','Label','Errors'))
		->setAttrib("class","menu-checkbox");

		$pwd = new Zend_Form_Element_Password('pwd');
		$pwd->addFilter('StripTags')
		->addFilter('StringTrim')
		->addValidator('StringLength', false, array(6))
		->setDecorators(array('ViewHelper','FormErrors','Label','Errors'))
		->setAttrib("class", "menu-input")
		->setAttrib("autocomplete", "off")
		->setAttrib("onKeyup", "pwdOk($('#pwd').val())");
		
		$pwd_verif = new Zend_Form_Element_Password('pwd_verif');
		$pwd_verif->addFilter('StripTags')
		->addFilter('StringTrim')
		->setDecorators(array('ViewHelper','FormErrors','Label','Errors'))
		->setAttrib("class", "menu-input")
		->setAttrib("autocomplete", "off")
		->setAttrib("onKeyup", "verifPwdOk($('#pwd_verif').val())");
		
		$db = new Application_Model_GroupesTable();
		$groupes = $db->fetchAll($db->select());
		$groupe_select = new Zend_Form_Element_Select('groupe');
		foreach($groupes as $g)
		{
			if($g['id_groupe'] != 1)
			{
				$groupe_select->addMultiOption($g['id_groupe'],$g['nom']);
			}
		}
		$groupe_select->setDecorators(array('ViewHelper','FormErrors','Label','Errors'));

		$admin_groupe = new Zend_Form_Element_Checkbox('admingroup');
		$admin_groupe->setValue(0)
		->setDecorators(array('ViewHelper','FormErrors','Label','Errors'))
		->setAttrib("class","menu-checkbox");
		
		$send = new Zend_Form_Element_Submit('send');
		$send->setAttrib('id','send_button')
		->setLabel('Enregistrer')
		->setAttrib('class','button')
		->setDecorators(array('ViewHelper','FormErrors','Errors'));

		$this->addElements(array($id,$login,$nom,$prenom,$promo,$pwd_enable,$pwd,$pwd_verif,$groupe_select,$admin_groupe,$send));
	}

}
